﻿using Common;
using DataAccess;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataBusiness
{
    public class WellBLL
    { 
        public static DataTable GetWell(int AreaID,string WellNo)
        {
            string sSql ="select * from tb_Well where AreaID = "+AreaID+" and WellNo = '"+WellNo+"'";
            DataTable initDt;
            initDt = SqlHelper.QuerySql(sSql).Tables[0];
            initDt.Columns[0].ColumnName = "井号";
            initDt.Columns[1].ColumnName = "区块编号";
            initDt.Columns[2].ColumnName = "井别";
            initDt.Columns[3].ColumnName = "井型";
            initDt.Columns[4].ColumnName = "地理位置";
            initDt.Columns[5].ColumnName = "地面海拔(m)";
            initDt.Columns[6].ColumnName = "X坐标(m)";
            initDt.Columns[7].ColumnName = "Y坐标(m)";
            initDt.Columns[8].ColumnName = "目的层";
            initDt.Columns[9].ColumnName = "完钻层位";
            initDt.Columns[10].ColumnName = "完钻井深";
            initDt.Columns[11].ColumnName = "人工井底";
            initDt.Columns[12].ColumnName = "完钻方式";
            initDt.Columns[13].ColumnName = "开钻日期";
            initDt.Columns[14].ColumnName = "完钻日期";
            initDt.Columns[15].ColumnName = "完井日期";
            return initDt;         
        }

        public static DataTable GetWellTrajectory(string WellNo)
        {
            string sSql = "select * from  tb_WellTrajectory where WellNo = '" + WellNo + "'";
            DataTable initDt = SqlHelper.QuerySql(sSql).Tables[0];
            initDt.Columns[0].ColumnName = "井眼轨迹编号";
            initDt.Columns[1].ColumnName = "井号";
            initDt.Columns[2].ColumnName = "测深(m)";
            initDt.Columns[3].ColumnName = "井斜角(°)";
            initDt.Columns[4].ColumnName = "方位角(°)";
            initDt.Columns[5].ColumnName = "垂深(m)";
            initDt.Columns[6].ColumnName = "+北/-南(m)";
            initDt.Columns[7].ColumnName = "+东/-西(m)";
            initDt.Columns[8].ColumnName = "狗腿度(°/30m)";
            initDt.Columns[9].ColumnName = "造斜率(°/30m)";
            initDt.Columns[10].ColumnName = "备注";

            DataTable retDt = new DataTable();
            retDt.Columns.Add(new DataColumn("井眼轨迹编号", typeof(string)));
            retDt.Columns.Add(new DataColumn("井号", typeof(string)));
            retDt.Columns.Add(new DataColumn("测深(m)", typeof(string)));
            retDt.Columns.Add(new DataColumn("井斜角(°)", typeof(string)));
            retDt.Columns.Add(new DataColumn("方位角(°)", typeof(string)));
            retDt.Columns.Add(new DataColumn("垂深(m)", typeof(string)));
            retDt.Columns.Add(new DataColumn("+北/-南(m)", typeof(string)));
            retDt.Columns.Add(new DataColumn("+东/-西(m)", typeof(string)));
            retDt.Columns.Add(new DataColumn("狗腿度(°/30m)", typeof(string)));
            retDt.Columns.Add(new DataColumn("造斜率(°/30m)", typeof(string)));
            retDt.Columns.Add(new DataColumn("备注", typeof(string)));

            DataRow dr;
            foreach(DataRow row in initDt.Rows)
            {
                dr = retDt.NewRow();
                dr["井眼轨迹编号"] = row["井眼轨迹编号"];
                dr["井号"] = row["井号"];
                dr["测深(m)"] = row["测深(m)"];
                dr["井斜角(°)"] = row["井斜角(°)"];
                dr["方位角(°)"] = row["方位角(°)"];
                dr["垂深(m)"] = row["垂深(m)"];
                dr["+北/-南(m)"] = row["+北/-南(m)"];
                dr["+东/-西(m)"] = row["+东/-西(m)"];
                dr["狗腿度(°/30m)"] = row["狗腿度(°/30m)"];
                dr["造斜率(°/30m)"] = row["造斜率(°/30m)"];
                dr["备注"] = row["备注"];
                retDt.Rows.Add(dr);
            }
            return retDt;
        }

        public static DataSet GetWellStruct(string CasingProgram,string WellNo)
        {
            string sSql = null;
            if (CasingProgram != null)
            {
                 sSql = "SELECT ID,WellNo,CasingProgram,HoleSize,TotalDepth,WellSize,StartLocation,EndLocation,CementDepth,UserID,InputDate FROM [tb_HoleStructure] WHERE CasingProgram=" + CasingProgram + " AND WellNo=" + WellNo;
            }
            else 
            {
                 sSql = "SELECT ID,WellNo,CasingProgram,HoleSize,TotalDepth,WellSize,StartLocation,EndLocation,CementDepth,UserID,InputDate FROM [tb_HoleStructure] WHERE CasingProgram=" + CasingProgram + " AND WellNo=" + WellNo;
            }
            DataSet initDt;
            initDt = SqlHelper.QuerySql(sSql);
            initDt.Tables[0].Columns[1].ColumnName = "井号";
            initDt.Tables[0].Columns[2].ColumnName = "套管程序";
            initDt.Tables[0].Columns[3].ColumnName = "井眼尺寸(mm)";
            initDt.Tables[0].Columns[4].ColumnName = "完钻深度(m)";
            initDt.Tables[0].Columns[5].ColumnName = "尺寸(mm)";
            initDt.Tables[0].Columns[6].ColumnName = "下入井段开始(m)";
            initDt.Tables[0].Columns[7].ColumnName = "下入井段结束(m)";
            initDt.Tables[0].Columns[8].ColumnName = "套管鞋层位";
            initDt.Tables[0].Columns[9].ColumnName = "水泥反深(m)";
            return initDt;
        }
      
    }
}
